package cn.iocoder.yudao.module.alipay.util;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import io.swagger.v3.core.util.Json;

public class RequestUtil {

    public static JSONObject getAccessToken(String appid,String appSecret){
        String apiUrl =String.format(
                "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}",appid,appSecret);
        String body = HttpRequest.get(apiUrl).execute().body();
        return JSONObject.parseObject(body);
    }

    public static String getOpenIdByCode(String appid,String appSecret,String code){
        String apiUrl =String.format(
                "https://api.weixin.qq.com/sns/jscode2session?appid={}&secret={}&js_code={}&grant_type=authorization_code"
                ,appid,appSecret,code);
        String body = HttpRequest.get(apiUrl).execute().body();
        return body;
    }
}
